// pages/form/form.js
import * as echarts from '../../components/ec-canvas/echarts'
let chart=null
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ec:{
      onInit: initChart
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
})
function initChart(canvas,width,height,dpr){
  chart=echarts.init(canvas,null,{
    width: width,
    height: height,
    devicePixelRatio: dpr
  })
  canvas.setChart(chart)

  let option=getOption() //echarts配置信息
  chart.setOption(option)

  return chart
}

function getOption(){
  return {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        axisTick: {
          alignWithLabel: true
        }
      }
    ],
    yAxis: [
      {
        type: 'value'
      }
    ],
    series: [
      {
        name: 'Direct',
        type: 'bar',
        barWidth: '60%',
        data: [10, 52, 200, 334, 390, 330, 220]
      }
    ]
  };
}